package com.cn.jdia.dc.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cn.jdia.dc.model.Backupconfig;
import com.cn.jdia.dc.service.IBackupconfigService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
public class BackupModifyController {

	@Resource
	private IBackupconfigService backupconfigService;
	
	@RequestMapping(value = "/backupmodify")
	@ResponseBody
	public ModelAndView buModify() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("backupmodify");

		return mav;
	}

	@RequestMapping("/getbuconfigdata")
	@ResponseBody
	public String getDbConfigData() {
		
		JSONArray jsonData = new JSONArray();
		JSONObject jo = null;
		int count = 0;
		
		List<Backupconfig> backupconfig = backupconfigService.getAllBackupconfig();
		for(Backupconfig config :backupconfig){
			jo = new JSONObject();
			
			jo.put("project", config.getProject());
			jo.put("source", config.getSource());
			jo.put("sourcepath", config.getSourcepath());
			jo.put("path", config.getPath());
			jo.put("rule", config.getNamerule());
			jo.put("expired", config.getExpired());
			
			jsonData.add(jo);
			count++;
		}
		
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("rows", jsonData);
		jsonObject.put("total", count);
		
		return jsonObject.toString();
	}
}

